/**
 * Created by Administrator on 2018/10/28.
 */

function getPageHTML(data) {
    var recommendList = data.recommendList;
    var goodsList = data.scenesList;
    var usedList = data.showList;
    var $recommendList = $('#recommend-list');
    var $usedList = $('#used-list');
    var $goodsList = $('#goods-list');
    if (recommendList.length == 0) {
        $recommendList.parents('.item-content').hide();
    } else {
        var recommendHTML = '';
        recommendList.forEach(function (d) {
            recommendHTML += ('<div data-id="' + d.id + '" class="goods-item">' +
                '<img src="' + (d.imageUrl || '../images/goodsDefault1.png') + '"/>' +
                '<p class="goods-info">' + d.name + '</p></div>');
        });
        $recommendList.html(recommendHTML);
    }
    if (usedList.length == 0) {
        $usedList.parents('.item-content').hide();
    } else {
        var usedHTML = '';
        usedList.forEach(function (d) {
            usedHTML += ('<div class=""></div>');
        });

        $usedList.html(usedHTML);
    }
    if (goodsList.length == 0) {
        $goodsList.parents('.item-content').hide();
    } else {
        var goodsHTML = '';
        goodsList.forEach(function (d) {
            goodsHTML += ('<div class="goods-item bottom-item" data-id="' + d.id + '">' +
                '<img src="' + (d.imageUrl || '../images/goodsDefault2.png') + '"/>' +
                '<div class="goods-info">' +
                '<p>' + d.name + '</p>' +
                '<div class="pirce-box">' +
                '<span class="new-price">￥' + d.price + '</span>' +
                '<s class="old-price">￥' + d.dailyPrice + '</s>' +
                ' </div> ' +
                '</div> ' +
                '</div>');
        });
        $goodsList.html(goodsHTML);
    }
}

function initPageClick() {
    $('.goods-item').on('click', function () {
        var $this = $(this);
        var itemId = $this.attr('data-id');
        window.location.href = 'goodsDetail.html?id=' + itemId;
    })
}

$(function () {
    ajax({
        url: 'app/ad/getADInfo',
        data: {},
        success: function (d) {
            getPageHTML(d);
            initPageClick();

        },
        fail: function () {
            _alert('修改密码失败');
        }
    })
});